import * as THREE from 'three'
import createCamera from './createCamera.js'
import createControl from './createControl.js'

const initRenderer = function (context) {
  let {scene} = context
  let {camera, renderer} = createCamera(context)
  let {controls} = createControl({camera, renderer})

  const clock = new THREE.Clock()

  // 渲染
  const render = () => {
    renderer.render(scene, camera)
    // 控制器--锁定
    controls.update(clock.getDelta())
    // 鼠标、键盘事件
    requestAnimationFrame(render)
  }

  return {camera, renderer, controls, render}
}

export default initRenderer
